

$(document).ready(function() {
	userTable();
});



function userTable() {
	$('#TableContainer').jtable({

        // --- Field options ---
    	title: 					'Users',
        paging: 				true, // to show more than one page
        //pageSize:				10,
        sorting: 				true,
      	defaultSorting: 		'Type ASC', // ... or DESC
        deleteConfirmation:		true,
        dialogShowEffect:		'fade', //  blind, bounce, clip, drop, explode, fold, highlight, puff, pulsate, scale, shake, size, slide
        dialogHideEffect:		'blind',
        selectOnRowClick:		false,
        selectingCheckboxes:	false,
        selecting:				false,
        multiselect:			false,
        // ---------------------
        
        // actions -----
        actions: {
            //listAction: 	'/eclipseWP/RadicalBooking/en/Admin/listAction',
            listAction: 	window.baseUrl + '/listAction',
            createAction: 	window.baseUrl + '/createAction',
            updateAction: 	window.baseUrl + '/updateAction',
            deleteAction: 	window.baseUrl + '/deleteAction'
        },// -----------

        // show fields
        fields: {
        	id: {
             	key: 			true,
             	edit: 			false,
             	create: 		false,
            	list: 			false
            },
            active: {
                title: 			'Status',
                width:			'8%',
                type:			'checkbox',
                values:			{'0':'disabled','1':'Enabled'},
                defaultValue:	'1',
                edit:			true,
                create:			true,
                list:			true
            },
            groupname: {
                title: 			'group',
                options:		{'school':'school','hotel':'hotel'},
                width:			'10%',
                edit:			false,
                create:			true,
                list:			true
            },
            username: {
                title: 			'User',
                edit:			false,
                width:			'10%',
                create:			true,
                list:			true,
                inputClass: 	'validate[required]'
            },
            password: {
                title: 			'Password',
                type: 			'password',
                width:			'20%',
                edit:			false,
                create:			true,
                list: 			false,
                inputClass: 	'validate[required]'
            },
            email: {
                title: 			'mail',
                width:			'15%',
                edit:			false,
                create:			true,
                list:			true,
                inputClass: 	'validate[required,custom[email]]'
            },
            first_name: {
                title: 			'first name',
                edit:			true,
                create:			true,
                list:			true
            },
            last_name: {
                title: 			'last name',
                edit:			true,
                create:			true,
                list:			true
            },
            company: {
            	title:			'company',
            	edit: 			true,
            	create:			true,
            	list:			true
            },
            phone: {
            	title:			'phone',
            	edit: 			true,
            	create:			true,
            	list:			true
            }
        },
        formCreated: function(event,data) {
			data.form.find('input[name="username"]').addClass('validate[required]');
			data.form.find('input[name="email"]').addClass('validate[required,custom[email]]');
			data.form.find('input[name="password"]').addClass('validate[required]');
			data.form.find('input[name="first_name"]').addClass('validate[required]');
			data.form.find('input[name="last_name"]').addClass('validate[required]');
			data.form.validationEngine();
        },
        formSubmitting: function(event, data) {
            return data.form.validationEngine('validate');
        },
        formClosed: function(event, data) {
            data.form.validationEngine('hide');
            data.form.validationEngine('detach');
        }
        
    });

    // call listaction and load data from server into the table
    $('#TableContainer').jtable('load');
}